/*
  ******************************************************************************
  * File Name          : ec20_mqtt.h
  * Description        : This file provides code for the ec20 mqtt driver.
  * Author             : jackwang by jiawang16@foxmail.com
  * Date               : 2021-08-31
  ******************************************************************************
*/

#ifndef __MQTT_EC20_H__
#define __MQTT_EC20_H__

#ifdef __cplusplus
extern "C" {
#endif

/*! -------------------------------------------------------------------------- */
/*! Include headers */
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include "usart.h"

/*! macro defination for porting */
/*! ec20 uart default 115200 8 N 1 */
#define EC20_SENDDATA(a,b)        USART2_sendData(a,b)    /*! uart redefine */
#define EC20_SENDSTR(a)           USART2_sendString(a)
#define EC20_RXFLAG               usart2Rx.flag                        
#define EC20_RXBUFF               usart2Rx.buff
#define EC20_RXLEN                usart2Rx.size
#define EC20_BUFF_SIZE            UART2_BUFF_SIZE       /*! buffsize define */
#define EC20_DELAYMS              HAL_Delay
#define PRINT_ENABLE              0x10        /*! 0x00=enable, other=disable*/

/*! macro defination for porting */
typedef enum
{
    EC20_NORMAL = (uint8_t)0,
    EC20_ERROR_TIMEOUT,
    EC20_ERROR_POWER,
    EC20_ERROR_ATECHO,
    EC20_ERROR_CPIN,
    EC20_ERROR_CREG,
    EC20_ERROR_CIMI,
    EC20_ERROR_CGATT,
    EC20_ERROR_QMTOPEN,
    EC20_ERROR_QMTCONN,
    EC20_ERROR_QMTDISC,
    EC20_ERROR_QMTSUB,
    EC20_ERROR_QMTUNS,
    EC20_ERROR_QMTPUBEX
}EC20_status;

extern uint8_t mqtt_client_id;

/*! -------------------------------------------------------------------------- */
/*! Public function prototype */ 
EC20_status EC20_initialize(void);
EC20_status EC20_mqttClientCreate(uint8_t pClientID,char* pIPv4, uint32_t pPort);
EC20_status EC20_mqttClientConnectServer(uint8_t pClientID, char* pClientIDStr,char* pName, char* pPswd);
EC20_status EC20_mqttClientSubscribe(uint8_t pClientID, char* pTopic, uint8_t pQos);
EC20_status EC20_mqttClientUnSubscribe(uint8_t pClientID, char* pTopic);
EC20_status EC20_mqttClientPublish(uint8_t pClientID, char* pTopic, uint8_t pQos, uint8_t pRetain, uint8_t *pData, uint32_t pSize);
EC20_status EC20_mqttClientDisConnectServer(uint8_t pClientID);
extern void EC20_moduleHardReset(void);
size_t      EC20_getIMEI(char *pIMEIBuff);

#ifdef __cplusplus
}
#endif

#endif /* __MQTT_EC20_H__ */

